<template>
  <KView class="goods-detail-evaluate">
    <evaluate-item v-for="evaluate in evaluateList" :key="evaluate.id" :evaluate="evaluate"></evaluate-item>
    <KView class="goods-detail-evaluate-more" v-if="loading||pagination.hasNextPage()">
      <sys-loading v-if="loading" :size="60"></sys-loading>
      <KView v-else-if="pagination.hasNextPage()" class="goods-detail-evaluate-btn" @click="lookMore">查看更多</KView>
    </KView>
  </KView>
</template>

<script>
  import SysLoading from 'common/sysLoading';
  import EvaluateItem from './evaluateItem';

  export default {
    props: {
      evaluateList: {
        type: Array,
        required: true
      },
      pagination: {
        type: Object,
        required: true
      },
      nextDataFun: {
        type: Function,
        required: true
      }
    },

    data() {
      return {
        loading: false
      };
    },

    methods: {
      lookMore() {
        if (this.loading) {
          return;
        }

        let pagination = this.pagination;
        if (!pagination.hasNextPage()) {
          return;
        }

        pagination.nextPage();
        this.loading = true;
        this.nextDataFun().then(() => {
          this.loading = false;
        }).catch(() => {
          this.loading = false;
        });
      }
    },

    components: {
      SysLoading,
      EvaluateItem
    }
  };

</script>

<style lang="scss">
  .goods-detail-evaluate {
    .goods-evaluate-item {
      margin-bottom: formatPx(60);

      &:last-child {
        margin-bottom: 0;
      }
    }

    .goods-detail-evaluate-more {
      position: relative;
      padding: formatPx(50) 0;
      height: formatPx(66);

      .goods-detail-evaluate-btn {
        text-align: center;
        width: formatPx(255);
        height: 100%;
        line-height: formatPx(65);
        border: 1px solid #999999;
        font-size: formatPx(30);
        margin: auto;
        border-radius: formatPx(33);
      }
    }
  }

</style>
